package com.zzyl.serve.aop;

import com.zzyl.serve.constants.CacheKeysConstants;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.AfterReturning;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;

@Aspect
@Component
public class CacheClearAspect {
    @Autowired
    private RedisTemplate<Object, Object> redisTemplate;

    @AfterReturning("@annotation(com.zzyl.serve.annotation.LevelCacheClear)")
    public void clearLevelCache(JoinPoint joinPoint) {
        redisTemplate.delete(CacheKeysConstants.NURSING_LEVEL_ALL);
    }

    @AfterReturning("@annotation(com.zzyl.serve.annotation.ProjectCacheClear)")
    public void clearProjectCache(JoinPoint joinPoint) {
        redisTemplate.delete(CacheKeysConstants.NURSING_PROJECT_ALL);
    }

    @AfterReturning("@annotation(com.zzyl.serve.annotation.PlanCacheClear)")
    public void clearPlanCache(JoinPoint joinPoint) {
        redisTemplate.delete(CacheKeysConstants.NURSING_PLAN_ALL);
    }

}
